import {
  imageUrl
} from "../../utils/imageutil"
let app = getApp()
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    show:{
      type: Boolean,
      value: false
    },

    // 是否住家
    search: {
      type: String,
      value: ''
    },
    // 其实时间
    st: {
      type: String,
      value: ''
    },
    keys: {
      type: String,
      value: ''
    },
    et: {
      type: String,
      value: ''
    },
    // 类型
    type: {
      type: Number,
      value: 0
    },
    //金额
    money_st: {
      type: String,
      value: ''
    },
    money_et: {
      type: String,
      value: ''
    },
    searchself: {
      type: String,
      value: ''
    },
  },

  /**
   * 组件的初始数据
   */
  data: {
    imageUrl,
    navcurr: 1,
    page: 1,
    flag: true,
    keys: '',
    type: 0,
    navlist: [{
      title: '总单量',
      id: 1,
      type: 0
    }, {
      title: '今天订单',
      id: 2,
      type: 4
    }, {
      title: '待接单',
      id: 3,
      type: 1
    }, {
      title: '接单中',
      id: 4,
      type: 2
    }, {
      title: '已完成',
      id: 5,
      type: 3
    }],
    list: []
  },

  lifetimes: {
    ready: function () {
      this.ReleaseWorkLlist()
    },
  },

  methods: {
    ontop() {
      this.setData({
        list: [],
        flag: true,
        page: 1,
      })
      this.ReleaseWorkLlist();

    },
    ReleaseWorkLlist() {
      if (!this.data.flag) {
        return
      }
      app.globalData.post({
        data: {
          do: 'ReleaseWorkLlist',
          a: 'wxapp2',
          page: this.data.page,
          pagesize: 10,
          uid: wx.getStorageSync('userInfo').id,
          st: this.data.st / 1000,
          et: this.data.et / 1000 + 60 * 60 * 24,
          money_st: this.data.money_st,
          money_et: this.data.money_et,
          type: this.data.type,
          searchs: this.data.search,
          keys: this.data.keys,
          searchself: this.data.searchself
        }
      }).then(res => {
        wx.stopPullDownRefresh();
        if (res.data.data.length == 0) {
          this.setData({
            flag: false
          })
        } else {
          let arr = this.data.list.concat(res.data.data);
          this.setData({
            list: arr,
            flag: true,
            page: this.data.page + 1
          })
          let swip = []
          this.data.list.forEach((v, i) => {
            if (v.state != 8 && v.user_nickname) {
              swip.push('恭喜'+v.user_nickname+",接单成功！")
            }
          })
          this.triggerEvent('get_swip',swip)
        }
      })
    },

    getList() { //家政员列表
      if (!this.data.flag) {
        return
      }
      let data = {
        type: this.data.type,
        page: this.data.page,
        limit: 10,
        keys: this.data.keys
      }
      getApp().globalData.post('/mer/store/order/releaseWorkOrder', data).then(res => {
        wx.stopPullDownRefresh();
        if (res.data.data.length == 0) {
          this.setData({
            flag: false
          })
        } else {
          let arr = this.data.list.concat(res.data.data.list);
          this.setData({
            list: arr,
            page: this.data.page + 1
          })
        }
      })
    },
  }
})